package com.yunhai.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.model.entity.sys.SysVersionLastEntity;
import com.yunhai.model.entity.sys.SysVersionManageEntity;
import com.yunhai.model.entity.sys.VersionInfo;
import com.yunhai.system.service.VersionManageService;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.vo.sys.SysVersionManageVo;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/systems")
public class VersionManageController {

    @Resource
    private VersionManageService versionManageService;

    @PostMapping("/version")
    public Ret addVersionInfo(@RequestBody SysVersionManageVo sysVersionManageVo) throws Exception {
        versionManageService.addVersionInfo(sysVersionManageVo);
        return Ret.ok();
    }

    @PostMapping("/version/file")
    public Ret addVersionInfoByFile(@RequestParam("file") MultipartFile file,
           Long platformId, String platformName, String version, String remark ) throws Exception {

        SysVersionManageVo sysVersionManageVo = new SysVersionManageVo();
        sysVersionManageVo.setPlatformId(platformId)
                .setPlatformName(platformName)
                .setVersion(version)
                .setRemark(remark);
        versionManageService.addVersionInfo( file, sysVersionManageVo );
        return Ret.ok();
    }


    @GetMapping("/version/pagination")
    public Ret getVersionPagination(PaginationVo paginationVo) throws Exception {

        IPage page = versionManageService.getVersionPagination(paginationVo);
        return Ret.toPage(page);
    }


    @GetMapping("/version/{id}")
    public Ret getVersionDetail(@PathVariable("id") Long id) throws Exception {

        VersionInfo versionInfo = versionManageService.getVersionDetail(id);
        return Ret.ok(versionInfo);
    }


    /**
     * 删除版本信息
     * */
    @PostMapping("/version/batchRemove")
    public Ret batchRemoveVersionInfo( @RequestBody List<Long> ids ) throws Exception {

        versionManageService.batchRemoveVersionInfo(ids);
        return Ret.ok();
    }

}
